<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/vue/2.6.11/vue.min.js"></script>
</head>
<body>

    <div id="app">
        <h1>动态组件</h1>
        <div>
            <component :is="componentShow"></component>
        </div>
        <button @click="handleShowA">显示A</button>
        <button @click="handleShowB">显示B</button>
        <button @click="handleShowC">显示C</button>
    </div>

    <script>

        Vue.component('compA', {
            template:'<p>组件A</p>'
        })

        Vue.component('compB', {
            template:'<p>组件B</p>'
        })

        Vue.component('compC', {
            template:'<p>组件C</p>'
        })

        var app = new Vue({
            el:'#app',
            data:{
                componentShow: 'compB'
            },
            methods: {
                handleShowA:function(){
                    this.componentShow='compA'
                },
                handleShowB:function(){
                    this.componentShow='compB'
                },
                handleShowC:function(){
                    this.componentShow='compC'
                }
            },
        })
    </script>
    
</body>
</html>